package cn.gov.msa.util;

import java.io.IOException;

import org.dom4j.DocumentException;
import org.xmlpull.v1.XmlPullParserException;

import com.mgear.sms.ws.ISmsWebServiceProxy;
import com.mgear.sms.ws.SmsWebService;

import cn.gov.msa.model.SmsLog;
import cn.gov.msa.service.SmsLogService;
import net.sf.json.JSONObject;

public class SmsTools {//这个类应该可以直接用
	
	
	public static boolean sendMsg(String phone,String content,SmsLogService smsLogService) throws Exception {
		boolean result = false;
		String success = "0";
		try {
			ISmsWebServiceProxy sms = new ISmsWebServiceProxy();
			JSONObject jsonObj = new JSONObject();
			jsonObj.put("Phone", phone);
			jsonObj.put("MsgText", content);
			String resultCd = sms.sendSingle("1002", "123456", jsonObj.toString());//sendSingle参数说明 第一个是 应用系统编号，第二个是 应用密码
			JSONObject smsReturnObj = JSONObject.fromObject(resultCd);
			if (smsReturnObj.getString("Result").equalsIgnoreCase("1")) {
				result = true;
				success="1";
			}			
		} catch (Exception e) {
			e.printStackTrace();
		}
		SmsLog record=new SmsLog();
		record.setContent(content);
		record.setPhone(phone);
		record.setSuccess(success);
		record.setSuccess(success);
		if (smsLogService!=null) {
			try {
				smsLogService.insertSelective(record);
			} catch (Exception e) {
				e.printStackTrace();
			} 
		}
		return result;
	}
	public static void main(String[] args) {
		try {
			SmsTools.sendMsg("13794961693","测试发送",null);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
